<?php $auth=0; ?>
<?php include 'lib/includes.php'; ?>
<?php include 'partials/header_menu.php'; ?>
<script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="jquery/jquery-ui-1.11.2.custom/jquery-ui.min.js"></script>
<?php
$details='';$date='';$clientid='';$vendeurid='';$mid='';$mp='';
if(isset($_POST['details'])&&isset($_POST['date'])&&isset($_POST['vendeurid'])&&isset($_POST['clientid'])&&isset($_POST['mp'])&&isset($_POST['mid'])) 
{
		$details=$db->quote($_POST['details']);
		$date=$db->quote($_POST['date']);
		$vendeurid=$db->quote($_POST['vendeurid']);
		$clientid=$db->quote($_POST['clientid']);
		$mp=$db->quote($_POST['mp']);
		$mid=$db->quote($_POST['mid']);
		//mise à jour
		if(isset($_GET['id'])){
			$id=$db->quote($_GET['id']);
			$db->query("update prescription set prescriptionDetails=$details,prescriptionDate=$date,clientId=$clientid,vendeurId=$vendeurid,methodePayement=$mp,medicamentId=$mid where prescriptionId=$id");
			header('Location: /prescription/prescription.php');
			die();
		}
		else
		{
			$db->query("insert into prescription (prescriptionDetails,prescriptionDate,clientId,vendeurId,methodePayement,medicamentId)
			SELECT $details,$date,clientId,vendeurId,methodePayement,medicamentId from client,vendeur,methodepayement,medicament where client.clientId=$clientid and vendeur.vendeurId=$vendeurid and methodepayement.methodePayement=$mp and medicament.medicamentId=$mid");
			header('Location: /prescription/prescription.php');
			die();
		}
}

if(isset($_GET['id'])){
	
		$id=$db->quote($_GET['id']);
		$select=$db->query("select * from prescription inner join medicament on medicament.medicamentId=prescription.medicamentId inner join vendeur on prescription.vendeurId=vendeur.vendeurId inner join client on client.clientId=prescription.clientId inner join methodepayement on prescription.methodepayement=methodepayement.methodepayement");
	    $_POST=$select->fetch();
		$details=$db->quote($_POST['prescriptionDetails']);
		$date=$db->quote($_POST['prescriptionDate']);
		$clientid=$db->quote($_POST['clientId']);
        $vendeurid=$db->quote($_POST['vendeurId']);
		$mid=$db->quote($_POST['medicamentId']);
		$mp=$db->quote($_POST['methodePayement']);

	}

?>
<form class="form-horizontal" action="#" method="post">
<br>
;&nbsp;&nbsp;<h3><span class="titre">&nbsp;&nbspDétails de la prescription</span></h3>
<br>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">Prescription détailles :</label>
    <div class="col-sm-5">
     <input type="text" class="form-control"  name="details" value="<?php echo str_replace("'","",$details) ; ?>">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">Date du visite :</label>
    <div class="col-sm-5">
     <input type="text" class="form-control"  name="date" value="<?php echo str_replace("'","",$date) ; ?>">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">ID client:</label>
    <div class="col-sm-5">
     <input type="text" class="form-control"  name="clientid" value="<?php echo str_replace("'","",$clientid) ; ?>">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">ID du vendeur:</label>
    <div class="col-sm-5">
     <input type="text" class="form-control"  name="vendeurid" value="<?php echo str_replace("'","",$vendeurid) ; ?>">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">Médicament:</label>
    <div class="col-sm-5">
     <input type="text" class="form-control"  name="mid" value="<?php echo str_replace("'","",$mid) ; ?>">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">Méthode du payement:</label>
    <div class="col-sm-5">
     <input type="text" class="form-control"  name="mp" value="<?php echo str_replace("'","",$mp) ; ?>">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-4 col-sm-10">
      <button type="submit" class="btn btn-success">valider</button>
	  <a href="prescription.php" class="btn btn-default">annuler</a>
    </div>
  </div>
</form>
<?php include 'partials/footer.php'; ?>
